﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;


namespace Recette
{
	public partial class EnvoieMail: Form
	{
		public EnvoieMail()
		{
			InitializeComponent();
            comboBoxSujet.Items.Add("Bugs");
            comboBoxSujet.Items.Add("Idée");
            comboBoxSujet.SelectedValue = comboBoxSujet.Items[0];


		}

        private void buttonEnvoyer_Click(object sender, EventArgs e)
        {
        try
			{
				//envoi de l'e-mail
                 String subject = "[CRROC]"+comboBoxSujet.Text;
				MailMessage email=new MailMessage();

                SmtpClient smtpClient = new SmtpClient();

                smtpClient.Host = "smtp.gmail.com";   // We use gmail as our smtp client
                smtpClient.Port = 587;
                smtpClient.EnableSsl = true;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new System.Net.NetworkCredential("opicaud.mailbox@gmail.com", "$Ol#03:Pi");
                email.Subject = subject;
                email.From = new MailAddress("opicaud.mailbox@gmail.com");
                email.Subject = subject;
            email.To.Add(new MailAddress("opicaud.mailbox@gmail.com"));
                email.Body = richTextBoxMail.Text;
                if (richTextBoxMail.Text.Length != 0)

                    smtpClient.Send(email);
                else
                    throw new Exception();


                MessageBox.Show("Notification envoyée avec succés !", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Dispose();

			}
			catch (Exception exc)
			{
                MessageBox.Show(exc.Message);
			} 
        }
	}
}
